<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>美育儿-登录</title>
    <link rel="stylesheet" href="/static/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/admin/css/login.css"/>
</head>

<body class="beg-login-bg">
<div class="beg-login-box">
    <header>
        <h1>后台登录</h1>
    </header>
    <div class="beg-login-main">
        <form action="/login/login" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe612;</i>
                </label>
                <input type="text" name="userName" lay-verify="required" autocomplete="off" placeholder="这里输入登录名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="password" name="passWord" lay-verify="required" autocomplete="off" placeholder="这里输入密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="beg-pull-right">
                    <button class="layui-btn layui-btn-primary" lay-submit lay-filter="login">
                        <i class="layui-icon">&#xe650;</i> 登录
                    </button>
                </div>
                <div class="beg-clear"></div>
            </div>
        </form>
    </div>
    <footer>
        <p>美育儿 meiyuer.com</p>
    </footer>
</div>
<script type="text/javascript" src="/static/admin/plugins/layui/layui.js"></script>
<script>
    if(window.top!=window){
        window.top.location.href=document.location.href;
    }
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form();
        form.on('submit(login)', function (data) {
            var url = $(data.form).attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data:  data.field,
                async: true,
                beforeSend: function () {
                    jz = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                error: function (request) {
                    layer.close(jz);
                    layer.alert('网络错误',{icon:2}, function(index){
                        layer.close(index);
                    });
                },
                success: function (data) {
                    //关闭加载层
                    layer.close(jz);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        }, function(){
                            window.location.href = data.data.url;
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
